﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Cemit.PolyServer
{
    /// <summary>
    /// 管理所有在线的玩家
    /// </summary>
    public class Players : IPlayers
    {
        private readonly Dictionary<string, Player> idPlayerPairs = new Dictionary<string, Player>();

        public bool Contains(string id)
        {
            return idPlayerPairs.ContainsKey(id);
        }

        public ICollection<Player> GetPlayers()
        {
            return idPlayerPairs.Values;
        }

        public Player GetPlayer(string id)
        {
            if (!idPlayerPairs.ContainsKey(id))
            {
                return null;
            }

            return idPlayerPairs[id];
        }

        public bool AddPlayer(Player player)
        {
            if (idPlayerPairs.ContainsKey(player.ID))
            {
                return false;
            }
            idPlayerPairs.Add(player.ID, player);
            return true;
        }

        public IPlayers RemovePlayer(string id)
        {
            idPlayerPairs.Remove(id);
            return this;
        }
    }
}
